package com.fzshang.commen.util.pay;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * @author 张子艺
 * @packge com.xbxkj.util
 * @data 2019-06-04 11:11
 * @project GoodLuck
 */
public class SenSms {
    public static boolean send(String phone) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAIsuabW482Dvrs", "wfXqd3d2ImyXDldUu4D6BArIMfMJwS");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        //request.setProtocol(ProtocolType.HTTPS);
        String code=Code.createCodeShu();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "弘言科技");
        request.putQueryParameter("TemplateCode", "SMS_167025148");
        request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
                if(response.getHttpStatus()==200){
                    EhcacheUtil.put("phone",phone,code);
                    return true;
                }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return  false;
    }
}
